package ru.stepuk.modern.nodes;

import org.apache.commons.collections15.Factory;
import ru.stepuk.modern.Model;
import ru.stepuk.modern.Timeline;
import ru.stepuk.modern.nodes.buffers.*;
import ru.stepuk.modern.distributions.DistributionFactory;
import ru.stepuk.modern.generators.RandomNumberGenerator;
import ru.stepuk.modern.Controller;
import ru.stepuk.modern.nodes.servers.*;

/**
 *
 * @author ivan
 */
public class NodeFactory implements Factory<Node> {

    private Controller controller;
    private Timeline timeline;
    private DistributionFactory df;
    private Model model;

    public NodeFactory(Model model, Controller controller, Timeline timeline, DistributionFactory df) {
        this.controller = controller;
        this.timeline = timeline;
        this.df = df;
        this.model = model;
    }

    public Node create() {

        switch (controller.getNodeToPlace()) {
            case SOURCE_EXPONENTIAL:
                return new Source(model, df.createExponential(), timeline);
            case SOURCE_ERLANG:
                return new Source(model, df.createErlang(), timeline);
            case SOURCE_UNIFORM:
                return new Source(model, df.createUniform(), timeline);
            case SOURCE_CONSTANT:
                return new Source(model, df.createDegenerate(), timeline);
            case SOURCE_DISCRETE:
                return new Source(model, df.createDiscrete(), timeline);
            case SERVER_SIMPLE:
                return new SimpleServer(model, timeline, df.createExponential());
            case SERVER_PRIORITY:
                return new PriorityServer(model, timeline, df.createExponential());
            case SERVER_QUANTUM:
                return new QuantumServer(model, timeline, df.createExponential());
            case BUFFER_QUEUE:
                return new Queue(model);
            case BUFFER_STACK:
                return new Stack(model);
            case BUFFER_PRIORITY:
                return new PriorityQueue(model);
            case BUFFER_RANDOM:
                return new RandomAccessQueue(model);
            case COND_SERVED:
                return new RequestFilter(model);
            case COND_SERVERS:
                return null;
            case COND_RANDOM:
                return new RandomCond(model, model.getGenerator());
            case MISC_ANCHOR:
                return new Anchor(model);
            case MISC_PRIOR:
                return new PrioritySetter(model);
            case MISC_EXIT:
                return new Exit(model);
            default:
                return null;
        }

    }
}
